package diveplanner;

/**
 * @author Bucatini
 * 
 * USE THESE TABLES AND INSTRUCTIONS:
 * http://elearning.padi.com/company0/tools/RDP%20InsforUseMet.pdf
 * http://elearning.padi.com/company0/tools/RDP_Table%20Met.pdf
 * 
 * ALL MEASUREMENTS ARE IN METRIC; use meters, not feet, for distance!
 * 
 * 
 * DISCLAIMER:
 * This software is made by amateurs for a software design project. This dive planner 
 * must never be used to plan real dives. We, the authors, will not be held responsible 
 * for any damages or injury resulting in usage of this software for live usage. Instead, 
 * treat this software as an exercise in good software design and the exploration of what 
 * makes usable programs and interfaces.
 * 
 * 2014-11-14
 * A major note: this dive table is for recreational diving, not for professionals who need to plan 
 * decompression stops. Recreational divers only calculate how slow to go WITHOUT having 
 * to stop.
 * 
 * Always include a 3-minute stop at 15 feet, and a 1.5 minute stop at maximum depth.
 * 
 * Do not ascend faster than 30 feet per minute.
 * 
 * Input: desired depth
 * Output: how long the trip will take, and information about details of the trip such as dive speed 
 * and total duration of the trip itself.
 * 
 * 
 * 
 */

public class DiveTable {
   
	private boolean debug = false;
	
	//for Justin's residualNitro() method
	private int nitroMinutes = 0;
	
	
	
	/**
	 * Enter in the desired dive depth to receive the maximum allowable dive time. There are lots of 
	 * conditionals for any given depth which this code must parse. 
	 * 
	 * 
	 * @param depth
	 * @return minutes and/or dive safety allowance
	 * 
	 * If the return value is zero or less, then an error has occurred! Make sure if you call this 
	 * method, check to see the value being returned! There should never be a negative value in the 
	 * dive table! 
	 */
    public int maxTimeAllowed(int depth)  {
    	int max = -1;
    	
    	if(debug)  {
    		System.out.println("DEBUG: maxTimeAllowed param depth = " + depth);
    	}
    	
    	if(depth <= 0)  {
    		//generic error state
    		depth = -1;
    		max = -1;
    	}
    	else if(depth <= 10)  {
    		//anything less than 10 meters is rounded up to 10 meters
    		depth = 10;
    		max = 219;
    	}
    	else if(depth <= 12)  {
    		//round up
    		depth = 12;
    		max = 147;
    	}
    	else if(depth <= 14)  {
    		depth = 14;
    		max = 98;
    	}
    	else if(depth <= 16)  {
    		depth = 16;
    		max = 72;
    	}
    	else if(depth <= 18)  {
    		depth = 18;
    		max = 56;
    	}
    	else if(depth <= 20)  {
    		depth = 20;
    		max = 45;
    	}
    	else if(depth <= 22)  {
    		depth = 22;
    		max = 37;
    	}
    	else if(depth <= 25)  {
    		depth = 25;
    		max = 29;
    	}
    	else if(depth <= 30)  {
    		depth = 30;
    		max = 20;
    	}
    	else if(depth <= 35)  {
    		depth = 35;
    		max = 14;
    	}
    	else if(depth <= 40)  {
    		depth = 40;
    		max = 9;
    	}
    	else if(depth <= 42)  {
    		depth = 42;
    		max = 8;
    	}
    	else  {
    		//if a value is too high, then error should occur
    		depth = -1;
    	}
    	
    	//if -1 returned, then an error of some kind has occurred.
    	return max;
    	
    }  //end of maxTimeAllowed() method
    
    /**
     * This method looks at the diver's previous depth, the time they spent there, the time rested at the surface,
     * what the next depth they want to dive to is, and how many minutes of nitrogen are already in the diver's blood,
     * and it calculates how many minutes of nitrogen will be in the diver's blood on the next dive.
     * This method aims to simulate the functionality of the dive planning card.
     * 
     * 
     * @param depth
     * @param time
     * @param surfaceTime
     * @param nextDepth
     * @param nitroMinutes
     * @return minutes of nitrogen in blood
     * 
     * If the return value is zero or less, then an error has occurred! Make sure if you call this 
     * method, check to see the value being returned! There should never be a negative value in the 
     * dive table! 
     */
    public int residualNitro (int depth, int time, int surfaceTime, int nextDepth, int nitroMinutes) {
      
      int resid = -1;
      int pressureGroup = -1;
      int surfaceGroup = -1;
      
      //created a private variable for the DiveTable at the top
      //private int nitroMinutes = 0;
      //this value can be updated as the table is used.
      
      if (depth <= 0 || time <= 0 || surfaceTime < 0 || nextDepth <= 0 || nitroMinutes < 0) {

        resid = -1;
        
      } else {
        
        time = time + nitroMinutes;
        
        // The first part of the dive planning card.  This part of the method looks at how long the diver stays at
        // the current depth.  It assigns them a pressure group.
        if (depth <= 10) {
        
          if (time <= 10) {
         
            pressureGroup = 1;
          
        } else if (time <= 20) {
          
          pressureGroup = 2;
          
        } else if (time <= 26) {
          
          pressureGroup = 3;
          
        } else if (time <= 30) {
          
          pressureGroup = 4;
          
        } else if (time <= 34) {
          
          pressureGroup = 5;
          
        } else if (time <= 37) {
          
          pressureGroup = 6;
          
        } else if (time <= 41) {
          
          pressureGroup = 7;
          
        } else if (time <= 45) {
          
          pressureGroup = 8;
          
        } else if (time <= 50) {
          
          pressureGroup = 9;
          
        } else if (time <= 54) {
          
          pressureGroup = 10;
          
        } else if (time <= 59) {
          
          pressureGroup = 11;
          
        } else if (time <= 64) {
          
          pressureGroup = 12;
          
        } else if (time <= 70) {
          
          pressureGroup = 13;
          
        } else if (time <= 75) {
          
          pressureGroup = 14;
          
        } else if (time <= 82) {
          
          pressureGroup = 15;
          
        } else if (time <= 88) {
          
          pressureGroup = 16;
          
        } else if (time <= 95) {
          
          pressureGroup = 17;
          
        } else if (time <= 104) {
          
          pressureGroup = 18;
          
        } else if (time <= 112) {
          
          pressureGroup = 19;
          
        } else if (time <= 122) {
          
          pressureGroup = 20;
          
        } else if (time <= 133) {
          
          pressureGroup = 21;
          
        } else if (time <= 145) {
          
          pressureGroup = 22;
          
        } else if (time <= 160) {
          
          pressureGroup = 23;
          
        } else if (time <= 178) {
          
          pressureGroup = 24;
          
        } else if (time <= 199) {
          
          pressureGroup = 25;
          
        } else if (time <= 219) {
          
          pressureGroup = 26;
          
        }
        
      } else if (depth <= 12) {
        
        if (time <= 9) {
          
          pressureGroup = 1;
          
        } else if (time <= 17) {
          
          pressureGroup = 2;
          
        } else if (time <= 23) {
          
          pressureGroup = 3;
          
        } else if (time <= 26) {
          
          pressureGroup = 4;
          
        } else if (time <= 29) {
          
          pressureGroup = 5;
          
        } else if (time <= 32) {
          
          pressureGroup = 6;
          
        } else if (time <= 35) {
          
          pressureGroup = 7;
          
        } else if (time <= 38) {
          
          pressureGroup = 8;
          
        } else if (time <= 42) {
          
          pressureGroup = 9;
          
        } else if (time <= 45) {
          
          pressureGroup = 10;
          
        } else if (time <= 49) {
          
          pressureGroup = 11;
          
        } else if (time <= 53) {
          
          pressureGroup = 12;
          
        } else if (time <= 57) {
          
          pressureGroup = 13;
          
        } else if (time <= 62) {
          
          pressureGroup = 14;
          
        } else if (time <= 66) {
          
          pressureGroup = 15;
          
        } else if (time <= 71) {
          
          pressureGroup = 16;
          
        } else if (time <= 76) {
          
          pressureGroup = 17;
          
        } else if (time <= 82) {
          
          pressureGroup = 18;
          
        } else if (time <= 88) {
          
          pressureGroup = 19;
          
        } else if (time <= 94) {
          
          pressureGroup = 20;
          
        } else if (time <= 101) {
          
          pressureGroup = 21;
          
        } else if (time <= 108) {
          
          pressureGroup = 22;
          
        } else if (time <= 116) {
          
          pressureGroup = 23;
          
        } else if (time <= 125) {
          
          pressureGroup = 24;
          
        } else if (time <= 134) {
          
          pressureGroup = 25;
          
        } else if (time <= 147) {
          
          pressureGroup = 26;
          
        }
        
      } else if (depth <= 14) {
        
        if (time <= 8) {
          
          pressureGroup = 1;
          
        } else if (time <= 15) {
          
          pressureGroup = 2;
          
        } else if (time <= 19) {
          
          pressureGroup = 3;
          
        } else if (time <= 22) {
          
          pressureGroup = 4;
          
        } else if (time <= 24) {
          
          pressureGroup = 5;
          
        } else if (time <= 27) {
          
          pressureGroup = 6;
          
        } else if (time <= 29) {
          
          pressureGroup = 7;
          
        } else if (time <= 32) {
          
          pressureGroup = 8;
          
        } else if (time <= 35) {
          
          pressureGroup = 9;
          
        } else if (time <= 37) {
          
          pressureGroup = 10;
          
        } else if (time <= 40) {
          
          pressureGroup = 11;
          
        } else if (time <= 43) {
          
          pressureGroup = 12;
          
        } else if (time <= 47) {
          
          pressureGroup = 13;
          
        } else if (time <= 50) {
          
          pressureGroup = 14;
          
        } else if (time <= 53) {
          
          pressureGroup = 15;
          
        } else if (time <= 57) {
          
          pressureGroup = 16;
          
        } else if (time <= 61) {
          
          pressureGroup = 17;
          
        } else if (time <= 64) {
          
          pressureGroup = 18;
          
        } else if (time <= 68) {
          
          pressureGroup = 19;
          
        } else if (time <= 73) {
          
          pressureGroup = 20;
          
        } else if (time <= 77) {
          
          pressureGroup = 21;
          
        } else if (time <= 82) {
          
          pressureGroup = 22;
          
        } else if (time <= 87) {
          
          pressureGroup = 23;
          
        } else if (time <= 92) {
          
          pressureGroup = 24;
          
        } else if (time <= 98) {
          
          pressureGroup = 25;
          
        }
        
      } else if (depth <= 16) {
        
        if (time <= 7) {
          
          pressureGroup = 1;
          
        } else if (time <= 13) {
          
          pressureGroup = 2;
          
        } else if (time <= 17) {
          
          pressureGroup = 3;
          
        } else if (time <= 19) {
          
          pressureGroup = 4;
          
        } else if (time <= 21) {
          
          pressureGroup = 5;
          
        } else if (time <= 23) {
          
          pressureGroup = 6;
          
        } else if (time <= 25) {
          
          pressureGroup = 7;
          
        } else if (time <= 27) {
          
          pressureGroup = 8;
          
        } else if (time <= 29) {
          
          pressureGroup = 9;
          
        } else if (time <= 32) {
          
          pressureGroup = 10;
          
        } else if (time <= 34) {
          
          pressureGroup = 11;
          
        } else if (time <= 37) {
          
          pressureGroup = 12;
          
        } else if (time <= 39) {
          
          pressureGroup = 13;
          
        } else if (time <= 42) {
          
          pressureGroup = 14;
          
        } else if (time <= 45) {
          
          pressureGroup = 15;
          
        } else if (time <= 48) {
          
          pressureGroup = 16;
          
        } else if (time <= 50) {
          
          pressureGroup = 17;
          
        } else if (time <= 53) {
          
          pressureGroup = 18;
          
        } else if (time <= 56) {
          
          pressureGroup = 19;
          
        } else if (time <= 60) {
          
          pressureGroup = 20;
          
        } else if (time <= 63) {
          
          pressureGroup = 21;
          
        } else if (time <= 67) {
          
          pressureGroup = 22;
          
        } else if (time <= 70) {
          
          pressureGroup = 23;
          
        } else if (time <= 72) {
          
          pressureGroup = 24;
          
        }
        
      } else if (depth <= 18) {
        
        if (time <= 6) {
          
          pressureGroup = 1;
          
        } else if (time <= 11) {
          
          pressureGroup = 2;
          
        } else if (time <= 15) {
          
          pressureGroup = 3;
          
        } else if (time <= 16) {
          
          pressureGroup = 4;
          
        } else if (time <= 18) {
          
          pressureGroup = 5;
          
        } else if (time <= 21) {
          
          pressureGroup = 6;
          
        } else if (time <= 23) {
          
          pressureGroup = 7;
          
        } else if (time <= 25) {
          
          pressureGroup = 8;
          
        } else if (time <= 26) {
          
          pressureGroup = 9;
          
        } else if (time <= 28) {
          
          pressureGroup = 10;
          
        } else if (time <= 30) {
          
          pressureGroup = 11;
          
        } else if (time <= 32) {
          
          pressureGroup = 12;
          
        } else if (time <= 34) {
          
          pressureGroup = 13;
          
        } else if (time <= 36) {
          
          pressureGroup = 14;
          
        } else if (time <= 39) {
          
          pressureGroup = 15;
          
        } else if (time <= 41) {
          
          pressureGroup = 16;
          
        } else if (time <= 43) {
          
          pressureGroup = 17;
          
        } else if (time <= 46) {
          
          pressureGroup = 18;
          
        } else if (time <= 48) {
          
          pressureGroup = 19;
          
        } else if (time <= 51) {
          
          pressureGroup = 20;
          
        } else if (time <= 53) {
          
          pressureGroup = 21;
          
        } else if (time <= 55) {
          
          pressureGroup = 22;
          
        } else if (time <= 56) {
          
          pressureGroup = 23;
          
        }
        
      } else if (depth <= 20) {
        
        if (time <= 6) {
          
          pressureGroup = 1;
          
        } else if (time <= 10) {
          
          pressureGroup = 2;
          
        } else if (time <= 13) {
          
          pressureGroup = 3;
          
        } else if (time <= 15) {
          
          pressureGroup = 4;
          
        } else if (time <= 16) {
          
          pressureGroup = 5;
          
        } else if (time <= 18) {
          
          pressureGroup = 6;
          
        } else if (time <= 20) {
          
          pressureGroup = 7;
          
        } else if (time <= 21) {
          
          pressureGroup = 8;
          
        } else if (time <= 23) {
          
          pressureGroup = 9;
          
        } else if (time <= 25) {
          
          pressureGroup = 10;
          
        } else if (time <= 26) {
          
          pressureGroup = 11;
          
        } else if (time <= 28) {
          
          pressureGroup = 12;
          
        } else if (time <= 30) {
          
          pressureGroup = 13;
          
        } else if (time <= 32) {
          
          pressureGroup = 14;
          
        } else if (time <= 34) {
          
          pressureGroup = 15;
          
        } else if (time <= 36) {
          
          pressureGroup = 16;
          
        } else if (time <= 38) {
          
          pressureGroup = 17;
          
        } else if (time <= 40) {
          
          pressureGroup = 18;
          
        } else if (time <= 42) {
          
          pressureGroup = 19;
          
        } else if (time <= 44) {
          
          pressureGroup = 20;
          
        } else if (time <= 45) {
          
          pressureGroup = 21;
          
        }
        
      } else if (depth <= 22) {
        
        if (time <= 5) {
          
          pressureGroup = 1;
          
        } else if (time <= 9) {
          
          pressureGroup = 2;
          
        } else if (time <= 12) {
          
          pressureGroup = 3;
          
        } else if (time <= 13) {
          
          pressureGroup = 4;
          
        } else if (time <= 15) {
          
          pressureGroup = 5;
          
        } else if (time <= 16) {
          
          pressureGroup = 6;
          
        } else if (time <= 18) {
          
          pressureGroup = 7;
          
        } else if (time <= 19) {
          
          pressureGroup = 8;
          
        } else if (time <= 21) {
          
          pressureGroup = 9;
          
        } else if (time <= 22) {
          
          pressureGroup = 10;
          
        } else if (time <= 24) {
          
          pressureGroup = 11;
          
        } else if (time <= 25) {
          
          pressureGroup = 12;
          
        } else if (time <= 27) {
          
          pressureGroup = 13;
          
        } else if (time <= 29) {
          
          pressureGroup = 14;
          
        } else if (time <= 30) {
          
          pressureGroup = 15;
          
        } else if (time <= 32) {
          
          pressureGroup = 16;
          
        } else if (time <= 34) {
          
          pressureGroup = 17;
          
        } else if (time <= 36) {
          
          pressureGroup = 18;
          
        } else if (time <= 37) {
          
          pressureGroup = 19;
          
        }
        
      } else if (depth <= 25) {
        
        if (time <= 4) {
          
          pressureGroup = 1;
          
        } else if (time <= 8) {
          
          pressureGroup = 2;
          
        } else if (time <= 10) {
          
          pressureGroup = 3;
          
        } else if (time <= 11) {
          
          pressureGroup = 4;
          
        } else if (time <= 13) {
          
          pressureGroup = 5;
          
        } else if (time <= 14) {
          
          pressureGroup = 6;
          
        } else if (time <= 15) {
          
          pressureGroup = 7;
          
        } else if (time <= 17) {
          
          pressureGroup = 8;
          
        } else if (time <= 18) {
          
          pressureGroup = 9;
          
        } else if (time <= 19) {
          
          pressureGroup = 10;
          
        } else if (time <= 21) {
          
          pressureGroup = 11;
          
        } else if (time <= 22) {
          
          pressureGroup = 12;
          
        } else if (time <= 23) {
          
          pressureGroup = 13;
          
        } else if (time <= 25) {
          
          pressureGroup = 14;
          
        } else if (time <= 26) {
          
          pressureGroup = 15;
          
        } else if (time <= 28) {
          
          pressureGroup = 16;
          
        } else if (time <= 29) {
          
          pressureGroup = 17;
          
        }
        
      } else if (depth <= 30) {
        
        if (time <= 3) {
          
          pressureGroup = 1;
          
        } else if (time <= 6) {
          
          pressureGroup = 2;
          
        } else if (time <= 8) {
          
          pressureGroup = 3;
          
        } else if (time <= 9) {
          
          pressureGroup = 4;
          
        } else if (time <= 10) {
          
          pressureGroup = 5;
          
        } else if (time <= 11) {
          
          pressureGroup = 6;
          
        } else if (time <= 12) {
          
          pressureGroup = 7;
          
        } else if (time <= 13) {
          
          pressureGroup = 8;
          
        } else if (time <= 14) {
          
          pressureGroup = 9;
          
        } else if (time <= 15) {
          
          pressureGroup = 10;
          
        } else if (time <= 16) {
          
          pressureGroup = 11;
          
        } else if (time <= 17) {
          
          pressureGroup = 12;
          
        } else if (time <= 19) {
          
          pressureGroup = 13;
          
        } else if (time <= 20) {
          
          pressureGroup = 14;
          
        }
        
      } else if (depth <= 35) {
        
        if (time <= 3) {
          
          pressureGroup = 1;
          
        } else if (time <= 5) {
          
          pressureGroup = 2;
          
        } else if (time <= 7) {
          
          pressureGroup = 3;
          
        } else if (time <= 8) {
          
          pressureGroup = 4;
          
        } else if (time <= 9) {
          
          pressureGroup = 6;
          
        } else if (time <= 10) {
          
          pressureGroup = 7;
          
        } else if (time <= 11) {
          
          pressureGroup = 8;
          
        } else if (time <= 12) {
          
          pressureGroup = 9;
          
        } else if (time <= 13) {
          
          pressureGroup = 10;
          
        } else if (time <= 14) {
          
          pressureGroup = 11;
          
        }
        
      } else if (depth <= 40) {
        
        if (time <= 5) {
          
          pressureGroup = 2;
          
        } else if (time <= 6) {
          
          pressureGroup = 3;
          
        } else if (time <= 7) {
          
          pressureGroup = 5;
          
        } else if (time <= 8) {
          
          pressureGroup = 6;
          
        } else if (time <= 9) {
          
          pressureGroup = 7;
          
        }
        
      } else if (depth <= 42) {
        
        if (time <= 4) {
          
          pressureGroup = 2;
          
        } else if (time <= 6) {
          
          pressureGroup = 4;
          
        } else if (time <= 7) {
          
          pressureGroup = 5;
          
        } else if (time <= 8) {
          
          pressureGroup = 6;
          
        }
        
      } else if (depth > 42) {
      // Error, users can't dive beyond 42 meters.
      
      }
      
      // The second part of the dive planning card.
      // For whatever pressure group the diver is in, they can choose to wait on the surface after their dive before
      // attempting another one.  How long they wait determines how much nitrogen escapes their bloodstream.
      if (pressureGroup == 1) {
       
        if (surfaceTime > 180) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 180) {
           
           surfaceGroup = 1; 
           
         }
        
      } else if (pressureGroup == 2) {
        
        if (surfaceTime > 228) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 228) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 47) {
          
           surfaceGroup = 2;
           
         }        
        
      } else if (pressureGroup == 3) {
        
        if (surfaceTime > 250) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 250) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 69) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 21) {
          
           surfaceGroup = 3;
           
         }  
        
      } else if (pressureGroup == 4) {
        
        if (surfaceTime > 259) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 259) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 78) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 30) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 8) {
          
           surfaceGroup = 4;
           
         } 
        
      } else if (pressureGroup == 5) {
        
        if (surfaceTime > 268) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 268) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 87) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 38) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 16) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 7) {
          
           surfaceGroup = 5;
           
         }
        
      } else if (pressureGroup == 6) {
        
        if (surfaceTime > 275) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 275) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 94) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 46) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 24) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 15) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 7) {
          
           surfaceGroup = 6;
           
         }
        
      } else if (pressureGroup == 7) {
        
        if (surfaceTime > 282) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 282) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 101) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 53) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 31) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 22) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 13) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 6) {
          
           surfaceGroup = 7;
           
         }
        
      } else if (pressureGroup == 8) {
        
        if (surfaceTime > 288) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 288) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 107) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 59) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 37) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 28) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 20) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 12) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 5) {
          
           surfaceGroup = 8;
           
         }
        
      } else if (pressureGroup == 9) {
        
        if (surfaceTime > 294) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 294) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 113) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 65) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 43) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 34) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 26) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 18) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 11) {
          
           surfaceGroup = 8;
           
         } if (surfaceTime <= 5) {
          
           surfaceGroup = 9;
           
         } 
        
      } else if (pressureGroup == 10) {
        
        if (surfaceTime > 300) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 300) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 119) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 71) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 49) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 40) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 31) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 24) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 17) {
          
           surfaceGroup = 8;
           
         } if (surfaceTime <= 11) {
          
           surfaceGroup = 9;
           
         } if (surfaceTime <= 5) {
          
           surfaceGroup = 10;
           
         }
        
      } else if (pressureGroup == 11) {
        
        if (surfaceTime > 305) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 305) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 124) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 76) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 54) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 45) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 37) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 29) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 22) {
          
           surfaceGroup = 8;
           
         } if (surfaceTime <= 16) {
          
           surfaceGroup = 9;
           
         } if (surfaceTime <= 10) {
          
           surfaceGroup = 10;
           
         } if (surfaceTime <= 4) {
          
           surfaceGroup = 11;
           
         }
        
      } else if (pressureGroup == 12) {
        
        if (surfaceTime > 310) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 310) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 129) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 81) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 59) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 50) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 42) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 34) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 27) {
          
           surfaceGroup = 8;
           
         } if (surfaceTime <= 21) {
          
           surfaceGroup = 9;
           
         } if (surfaceTime <= 15) {
          
           surfaceGroup = 10;
           
         } if (surfaceTime <= 9) {
          
           surfaceGroup = 11;
           
         } if (surfaceTime <= 4) {
          
           surfaceGroup = 12;
           
         }  
        
      } else if (pressureGroup == 13) {
        
        if (surfaceTime > 315) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 315) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 134) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 85) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 64) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 55) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 46) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 39) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 32) {
          
           surfaceGroup = 8;
           
         } if (surfaceTime <= 25) {
          
           surfaceGroup = 9;
           
         } if (surfaceTime <= 19) {
          
           surfaceGroup = 10;
           
         } if (surfaceTime <= 14) {
          
           surfaceGroup = 11;
           
         } if (surfaceTime <= 9) {
          
           surfaceGroup = 12;
           
         } if (surfaceTime <= 4) {
          
           surfaceGroup = 13;
           
         }
        
      } else if (pressureGroup == 14) {
        
        if (surfaceTime > 319) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 319) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 138) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 90) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 68) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 59) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 51) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 43) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 36) {
          
           surfaceGroup = 8;
           
         } if (surfaceTime <= 30) {
          
           surfaceGroup = 9;
           
         } if (surfaceTime <= 24) {
          
           surfaceGroup = 10;
           
         } if (surfaceTime <= 18) {
          
           surfaceGroup = 11;
           
         } if (surfaceTime <= 13) {
          
           surfaceGroup = 12;
           
         } if (surfaceTime <= 8) {
          
           surfaceGroup = 13;
           
         } if (surfaceTime <= 3) {
          
           surfaceGroup = 14;
           
         }        
        
      } else if (pressureGroup == 15) {
        
        if (surfaceTime > 324) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 324) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 143) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 94) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 72) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 63) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 55) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 47) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 41) {
          
           surfaceGroup = 8;
           
         } if (surfaceTime <= 34) {
          
           surfaceGroup = 9;
           
         } if (surfaceTime <= 28) {
          
           surfaceGroup = 10;
           
         } if (surfaceTime <= 23) {
          
           surfaceGroup = 11;
           
         } if (surfaceTime <= 17) {
          
           surfaceGroup = 12;
           
         } if (surfaceTime <= 12) {
          
           surfaceGroup = 13;
           
         } if (surfaceTime <= 8) {
          
           surfaceGroup = 14;
           
         } if (surfaceTime <= 3) {
          
           surfaceGroup = 15;
           
         }
        
      } else if (pressureGroup == 16) {
        
        if (surfaceTime > 328) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 328) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 147) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 98) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 76) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 67) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 59) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 51) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 45) {
          
           surfaceGroup = 8;
           
         } if (surfaceTime <= 38) {
          
           surfaceGroup = 9;
           
         } if (surfaceTime <= 32) {
          
           surfaceGroup = 10;
           
         } if (surfaceTime <= 27) {
          
           surfaceGroup = 11;
           
         } if (surfaceTime <= 21) {
          
           surfaceGroup = 12;
           
         } if (surfaceTime <= 16) {
          
           surfaceGroup = 13;
           
         } if (surfaceTime <= 12) {
          
           surfaceGroup = 14;
           
         } if (surfaceTime <= 7) {
          
           surfaceGroup = 15;
           
         } if (surfaceTime <= 3) {
          
           surfaceGroup = 16;
           
         }
        
      } else if (pressureGroup == 17) {
        
        if (surfaceTime > 331) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 331) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 150) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 102) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 80) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 71) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 63) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 55) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 48) {
          
           surfaceGroup = 8;
           
         } if (surfaceTime <= 42) {
          
           surfaceGroup = 9;
           
         } if (surfaceTime <= 36) {
          
           surfaceGroup = 10;
           
         } if (surfaceTime <= 30) {
          
           surfaceGroup = 11;
           
         } if (surfaceTime <= 25) {
          
           surfaceGroup = 12;
           
         } if (surfaceTime <= 20) {
          
           surfaceGroup = 13;
           
         } if (surfaceTime <= 16) {
          
           surfaceGroup = 14;
           
         } if (surfaceTime <= 11) {
          
           surfaceGroup = 15;
           
         } if (surfaceTime <= 7) {
          
           surfaceGroup = 16;
           
         } if (surfaceTime <= 3) {
          
           surfaceGroup = 17;
           
         }
        
      } else if (pressureGroup == 18) {
        
        if (surfaceTime > 335) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 335) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 154) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 106) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 84) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 75) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 67) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 59) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 52) {
          
           surfaceGroup = 8;
           
         } if (surfaceTime <= 46) {
          
           surfaceGroup = 9;
           
         } if (surfaceTime <= 40) {
          
           surfaceGroup = 10;
           
         } if (surfaceTime <= 34) {
          
           surfaceGroup = 11;
           
         } if (surfaceTime <= 29) {
          
           surfaceGroup = 12;
           
         } if (surfaceTime <= 24) {
          
           surfaceGroup = 13;
           
         } if (surfaceTime <= 19) {
          
           surfaceGroup = 14;
           
         } if (surfaceTime <= 15) {
          
           surfaceGroup = 15;
           
         } if (surfaceTime <= 11) {
          
           surfaceGroup = 16;
           
         } if (surfaceTime <= 7) {
          
           surfaceGroup = 17;
           
         } if (surfaceTime <= 3) {
          
           surfaceGroup = 18;
           
         }
        
      } else if (pressureGroup == 19) {
        
        if (surfaceTime > 339) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 339) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 158) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 109) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 87) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 78) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 70) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 63) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 56) {
          
           surfaceGroup = 8;
           
         } if (surfaceTime <= 49) {
          
           surfaceGroup = 9;
           
         } if (surfaceTime <= 43) {
          
           surfaceGroup = 10;
           
         } if (surfaceTime <= 38) {
          
           surfaceGroup = 11;
           
         } if (surfaceTime <= 32) {
          
           surfaceGroup = 12;
           
         } if (surfaceTime <= 27) {
          
           surfaceGroup = 13;
           
         } if (surfaceTime <= 23) {
          
           surfaceGroup = 14;
           
         } if (surfaceTime <= 18) {
          
           surfaceGroup = 15;
           
         } if (surfaceTime <= 14) {
          
           surfaceGroup = 16;
           
         } if (surfaceTime <= 10) {
          
           surfaceGroup = 17;
           
         } if (surfaceTime <= 6) {
          
           surfaceGroup = 18;
           
         } if (surfaceTime <= 3) {
          
           surfaceGroup = 19;
           
         }
        
      } else if (pressureGroup == 20) {
        
        if (surfaceTime > 342) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 342) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 161) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 113) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 91) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 82) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 73) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 66) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 59) {
          
           surfaceGroup = 8;
           
         } if (surfaceTime <= 53) {
          
           surfaceGroup = 9;
           
         } if (surfaceTime <= 47) {
          
           surfaceGroup = 10;
           
         } if (surfaceTime <= 41) {
          
           surfaceGroup = 11;
           
         } if (surfaceTime <= 36) {
          
           surfaceGroup = 12;
           
         } if (surfaceTime <= 31) {
          
           surfaceGroup = 13;
           
         } if (surfaceTime <= 26) {
          
           surfaceGroup = 14;
           
         } if (surfaceTime <= 22) {
          
           surfaceGroup = 15;
           
         } if (surfaceTime <= 17) {
          
           surfaceGroup = 16;
           
         } if (surfaceTime <= 13) {
          
           surfaceGroup = 17;
           
         } if (surfaceTime <= 10) {
          
           surfaceGroup = 18;
           
         } if (surfaceTime <= 6) {
          
           surfaceGroup = 19;
           
         } if (surfaceTime <= 2) {
          
           surfaceGroup = 20;
           
         }
        
      } else if (pressureGroup == 21) {
        
        if (surfaceTime > 345) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 345) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 164) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 116) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 94) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 85) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 77) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 69) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 62) {
          
           surfaceGroup = 8;
           
         } if (surfaceTime <= 56) {
          
           surfaceGroup = 9;
           
         } if (surfaceTime <= 50) {
          
           surfaceGroup = 10;
           
         } if (surfaceTime <= 44) {
          
           surfaceGroup = 11;
           
         } if (surfaceTime <= 39) {
          
           surfaceGroup = 12;
           
         } if (surfaceTime <= 34) {
          
           surfaceGroup = 13;
           
         } if (surfaceTime <= 30) {
          
           surfaceGroup = 14;
           
         } if (surfaceTime <= 25) {
          
           surfaceGroup = 15;
           
         } if (surfaceTime <= 21) {
          
           surfaceGroup = 16;
           
         } if (surfaceTime <= 17) {
          
           surfaceGroup = 17;
           
         } if (surfaceTime <= 13) {
          
           surfaceGroup = 18;
           
         } if (surfaceTime <= 9) {
          
           surfaceGroup = 19;
           
         } if (surfaceTime <= 6) {
          
           surfaceGroup = 20;
           
         } if (surfaceTime <= 2) {
          
           surfaceGroup = 21;
           
         }
        
      } else if (pressureGroup == 22) {
        
        if (surfaceTime > 348) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 348) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 167) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 119) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 97) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 88) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 80) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 72) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 65) {
          
           surfaceGroup = 8;
           
         } if (surfaceTime <= 59) {
          
           surfaceGroup = 9;
           
         } if (surfaceTime <= 53) {
          
           surfaceGroup = 10;
           
         } if (surfaceTime <= 47) {
          
           surfaceGroup = 11;
           
         } if (surfaceTime <= 42) {
          
           surfaceGroup = 12;
           
         } if (surfaceTime <= 37) {
          
           surfaceGroup = 13;
           
         } if (surfaceTime <= 33) {
          
           surfaceGroup = 14;
           
         } if (surfaceTime <= 28) {
          
           surfaceGroup = 15;
           
         } if (surfaceTime <= 24) {
          
           surfaceGroup = 16;
           
         } if (surfaceTime <= 20) {
          
           surfaceGroup = 17;
           
         } if (surfaceTime <= 16) {
          
           surfaceGroup = 18;
           
         } if (surfaceTime <= 12) {
          
           surfaceGroup = 19;
           
         } if (surfaceTime <= 9) {
          
           surfaceGroup = 20;
           
         } if (surfaceTime <= 5) {
          
           surfaceGroup = 21;
           
         } if (surfaceTime <= 2) {
          
           surfaceGroup = 22;
           
         }
        
      } else if (pressureGroup == 23) {
        
        if (surfaceTime > 351) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 351) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 170) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 122) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 100) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 91) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 83) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 75) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 68) {
          
           surfaceGroup = 8;
           
         } if (surfaceTime <= 62) {
          
           surfaceGroup = 9;
           
         } if (surfaceTime <= 56) {
          
           surfaceGroup = 10;
           
         } if (surfaceTime <= 50) {
          
           surfaceGroup = 11;
           
         } if (surfaceTime <= 45) {
          
           surfaceGroup = 12;
           
         } if (surfaceTime <= 40) {
          
           surfaceGroup = 13;
           
         } if (surfaceTime <= 36) {
          
           surfaceGroup = 14;
           
         } if (surfaceTime <= 31) {
          
           surfaceGroup = 15;
           
         } if (surfaceTime <= 27) {
          
           surfaceGroup = 16;
           
         } if (surfaceTime <= 23) {
          
           surfaceGroup = 17;
           
         } if (surfaceTime <= 19) {
          
           surfaceGroup = 18;
           
         } if (surfaceTime <= 15) {
          
           surfaceGroup = 19;
           
         } if (surfaceTime <= 12) {
          
           surfaceGroup = 20;
           
         } if (surfaceTime <= 8) {
          
           surfaceGroup = 21;
           
         } if (surfaceTime <= 5) {
          
           surfaceGroup = 22;
           
         } if (surfaceTime <= 2) {
          
           surfaceGroup = 23;
           
         }
        
      } else if (pressureGroup == 24) {
        
        if (surfaceTime > 354) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 354) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 173) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 125) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 103) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 94) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 86) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 78) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 71) {
          
           surfaceGroup = 8;
           
         } if (surfaceTime <= 65) {
          
           surfaceGroup = 9;
           
         } if (surfaceTime <= 59) {
          
           surfaceGroup = 10;
           
         } if (surfaceTime <= 53) {
          
           surfaceGroup = 11;
           
         } if (surfaceTime <= 48) {
          
           surfaceGroup = 12;
           
         } if (surfaceTime <= 43) {
          
           surfaceGroup = 13;
           
         } if (surfaceTime <= 39) {
          
           surfaceGroup = 14;
           
         } if (surfaceTime <= 34) {
          
           surfaceGroup = 15;
           
         } if (surfaceTime <= 30) {
          
           surfaceGroup = 16;
           
         } if (surfaceTime <= 26) {
          
           surfaceGroup = 17;
           
         } if (surfaceTime <= 22) {
          
           surfaceGroup = 18;
           
         } if (surfaceTime <= 18) {
          
           surfaceGroup = 19;
           
         } if (surfaceTime <= 15) {
          
           surfaceGroup = 20;
           
         } if (surfaceTime <= 11) {
          
           surfaceGroup = 21;
           
         } if (surfaceTime <= 8) {
          
           surfaceGroup = 22;
           
         } if (surfaceTime <= 5) {
          
           surfaceGroup = 23;
           
         } if (surfaceTime <= 2) {
          
           surfaceGroup = 24;
           
         }
        
      } else if (pressureGroup == 25) {
        
        if (surfaceTime > 357) {
          
          surfaceGroup = 0;
           
         } if (surfaceTime <= 357) {
           
           surfaceGroup = 1; 
           
         } if (surfaceTime <= 176) {
          
           surfaceGroup = 2;
           
         } if (surfaceTime <= 128) {
          
           surfaceGroup = 3;
           
         } if (surfaceTime <= 106) {
          
           surfaceGroup = 4;
           
         } if (surfaceTime <= 97) {
          
           surfaceGroup = 5;
           
         } if (surfaceTime <= 89) {
          
           surfaceGroup = 6;
           
         } if (surfaceTime <= 81) {
          
           surfaceGroup = 7;
           
         } if (surfaceTime <= 74) {
          
           surfaceGroup = 8;
           
         } if (surfaceTime <= 68) {
          
           surfaceGroup = 9;
           
         } if (surfaceTime <= 62) {
          
           surfaceGroup = 10;
           
         } if (surfaceTime <= 56) {
          
           surfaceGroup = 11;
           
         } if (surfaceTime <= 51) {
          
           surfaceGroup = 12;
           
         } if (surfaceTime <= 46) {
          
           surfaceGroup = 13;
           
         } if (surfaceTime <= 41) {
          
           surfaceGroup = 14;
           
         } if (surfaceTime <= 37) {
          
           surfaceGroup = 15;
           
         } if (surfaceTime <= 33) {
          
           surfaceGroup = 16;
           
         } if (surfaceTime <= 29) {
          
           surfaceGroup = 17;
           
         } if (surfaceTime <= 25) {
          
           surfaceGroup = 18;
           
         } if (surfaceTime <= 21) {
          
           surfaceGroup = 19;
           
         } if (surfaceTime <= 18) {
          
           surfaceGroup = 20;
           
         } if (surfaceTime <= 14) {
          
           surfaceGroup = 21;
           
         } if (surfaceTime <= 11) {
          
           surfaceGroup = 22;
           
         } if (surfaceTime <= 8) {
          
           surfaceGroup = 23;
           
         } if (surfaceTime <= 5) {
          
           surfaceGroup = 24;
           
         } if (surfaceTime <= 2) {
          
           surfaceGroup = 25;
           
         }
        
      } else if (pressureGroup == 26) {
        
        if (surfaceTime > 360) {
          
         surfaceGroup = 0;
          
        } if (surfaceTime <= 360) {
          
          surfaceGroup = 1; 
          
        } if (surfaceTime <= 179) {
         
          surfaceGroup = 2;
          
        } if (surfaceTime <= 131) {
         
          surfaceGroup = 3;
          
        } if (surfaceTime <= 109) {
         
          surfaceGroup = 4;
          
        } if (surfaceTime <= 100) {
         
          surfaceGroup = 5;
          
        } if (surfaceTime <= 91) {
         
          surfaceGroup = 6;
          
        } if (surfaceTime <= 84) {
         
          surfaceGroup = 7;
          
        } if (surfaceTime <= 77) {
         
          surfaceGroup = 8;
          
        } if (surfaceTime <= 71) {
         
          surfaceGroup = 9;
          
        } if (surfaceTime <= 65) {
         
          surfaceGroup = 10;
          
        } if (surfaceTime <= 59) {
         
          surfaceGroup = 11;
          
        } if (surfaceTime <= 54) {
         
          surfaceGroup = 12;
          
        } if (surfaceTime <= 49) {
         
          surfaceGroup = 13;
          
        } if (surfaceTime <= 44) {
         
          surfaceGroup = 14;
          
        } if (surfaceTime <= 40) {
         
          surfaceGroup = 15;
          
        } if (surfaceTime <= 35) {
         
          surfaceGroup = 16;
          
        } if (surfaceTime <= 31) {
         
          surfaceGroup = 17;
          
        } if (surfaceTime <= 28) {
         
          surfaceGroup = 18;
          
        } if (surfaceTime <= 24) {
         
          surfaceGroup = 19;
          
        } if (surfaceTime <= 20) {
         
          surfaceGroup = 20;
          
        } if (surfaceTime <= 17) {
         
          surfaceGroup = 21;
          
        } if (surfaceTime <= 14) {
         
          surfaceGroup = 22;
          
        } if (surfaceTime <= 11) {
         
          surfaceGroup = 23;
          
        } if (surfaceTime <= 8) {
         
          surfaceGroup = 24;
          
        } if (surfaceTime <= 5) {
         
          surfaceGroup = 25;
          
        } if (surfaceTime <= 2) {
         
          surfaceGroup = 26;
          
        }
        
      }
      
      // The third part of the dive planning card.
      // Based on the how long the diver will wait at the surface, there will be a certain amount on nitrogen in minutes
      // still in the diver's blood.  This also depends on how deep the diver wants their next dive to be.
      if (surfaceGroup == 0) {
        
        resid = 0;
        
      }
      
      if (surfaceGroup == 1) {
        
        if (nextDepth > 40) {
          
          // Error, user can't dive past 40 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 40) {
          
          resid = 2;
          
        }
        
        if (nextDepth <= 35) {
          
          resid = 3;
          
        }
        
        if (nextDepth <= 30) {
          
          resid = 3;
          
        }
        
        if (nextDepth <= 25) {
          
          resid = 4;
          
        }
        
        if (nextDepth <= 22) {
          
          resid = 5;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 6;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 6;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 7;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 8;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 9;
          
        }
          
        if (nextDepth <= 10) {
         
          resid = 10;
          
        }       
        
      }
      
      if (surfaceGroup == 2) {
        
        if (nextDepth > 40) {
          
          // Error, user can't dive past 40 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 40) {
          
          resid = 5;
          
        }
        
        if (nextDepth <= 35) {
          
          resid = 5;
          
        }
        
        if (nextDepth <= 30) {
          
          resid = 6;
          
        }
        
        if (nextDepth <= 25) {
          
          resid = 8;
          
        }
        
        if (nextDepth <= 22) {
          
          resid = 9;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 10;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 11;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 13;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 15;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 17;
          
        }
        
        if (nextDepth <= 10) {
          
          resid = 20;
          
        }

      }
      
      if (surfaceGroup == 3) {
        
        if (nextDepth > 35) {
          
          // Error, user can't dive past 35 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 35) {
          
          resid = 7;
          
        }       
        
        if (nextDepth <= 30) {
          
          resid = 8;
          
        }
        
        if (nextDepth <= 25) {
          
          resid = 10;
          
        }
        
        if (nextDepth <= 22) {
          
          resid = 12;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 13;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 15;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 17;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 19;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 23;
          
        }
        
        if (nextDepth <= 10) {
          
          resid = 26;
          
        } 

      }
      
      if (surfaceGroup == 4) {
        
        if (nextDepth > 35) {
          
          // Error, user can't dive past 35 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 35) {
          
          resid = 8;
          
        }       
        
        if (nextDepth <= 30) {
          
          resid = 9;
          
        }
        
        if (nextDepth <= 25) {
          
          resid = 11;
          
        }
        
        if (nextDepth <= 22) {
          
          resid = 13;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 15;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 16;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 19;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 22;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 26;
          
        }
        
        if (nextDepth <= 10) {
          
          resid = 30;
          
        }        

      }
      
      if (surfaceGroup == 5) {
        
        if (nextDepth > 35) {
          
          // Error, user can't dive past 35 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 35) {
          
          resid = 9;
          
        }       
        
        if (nextDepth <= 30) {
          
          resid = 10;
          
        }
        
        if (nextDepth <= 25) {
          
          resid = 13;
          
        }
        
        if (nextDepth <= 22) {
          
          resid = 15;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 16;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 18;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 21;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 24;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 29;
          
        }       
        
        if (nextDepth <= 10) {
          
          resid = 34;
          
        }
        
      }
      
      if (surfaceGroup == 6) {
        
        if (nextDepth > 35) {
          
          // Error, user can't dive past 35 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 35) {
          
          resid = 9;
          
        }       
        
        if (nextDepth <= 30) {
          
          resid = 11;
          
        }
        
        if (nextDepth <= 25) {
          
          resid = 14;
          
        }
        
        if (nextDepth <= 22) {
          
          resid = 16;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 18;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 20;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 23;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 27;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 32;
          
        }
              
        if (nextDepth <= 10) {
          
          resid = 37;
          
        }
        
      }
      
      if (surfaceGroup == 7) {
        
        if (nextDepth > 35) {
          
          // Error, user can't dive past 35 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 35) {
          
          resid = 10;
          
        }       
        
        if (nextDepth <= 30) {
          
          resid = 12;
          
        }
        
        if (nextDepth <= 25) {
          
          resid = 15;
          
        }
        
        if (nextDepth <= 22) {
          
          resid = 18;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 20;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 22;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 25;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 29;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 35;
          
        }
        
        if (nextDepth <= 10) {
          
          resid = 41;
          
        }    

      }
      
      if (surfaceGroup == 8) {
        
        if (nextDepth > 35) {
          
          // Error, user can't dive past 35 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 35) {
          
          resid = 10;
          
        }
        
        if (nextDepth <= 30) {
          
          resid = 13;
          
        }
        
        if (nextDepth <= 25) {
          
          resid = 17;
          
        }
        
        if (nextDepth <= 22) {
          
          resid = 19;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 21;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 24;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 27;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 32;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 38;
          
        } 
        
        if (nextDepth <= 10) {
          
          resid = 45;
          
        }
       
      }
      
      if (surfaceGroup == 9) {
        
        if (nextDepth > 30) {
          
          // Error, user can't dive past 30 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 30) {
          
          resid = 14;
          
        }
        
        if (nextDepth <= 25) {
          
          resid = 18;
          
        }
        
        if (nextDepth <= 22) {
          
          resid = 21;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 23;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 26;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 29;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 35;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 42;
          
        }        
        
        if (nextDepth <= 10) {
          
          resid = 50;
          
        }
        
      }
      
      if (surfaceGroup == 10) {
        
        if (nextDepth <= 10) {
          
          resid = 54;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 45;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 37;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 32;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 28;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 25;
          
        }
        
        if (nextDepth <= 22) {
          
          resid = 22;
          
        }
        
        if (nextDepth <= 25) {
          
          resid = 19;
          
        }
        
        if (nextDepth <= 30) {
          
          resid = 15;
          
        }
        
        if (nextDepth > 30) {
          
          // Error, user can't dive past 30 meters.
          resid = -1;
          
        }
        
      }      
      
      if (surfaceGroup == 11) {
        
        if (nextDepth > 30) {
          
          // Error, user can't dive past 30 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 30) {
          
          resid = 16;
          
        }
        
        if (nextDepth <= 25) {
          
          resid = 21;
          
        }
        
        if (nextDepth <= 22) {
          
          resid = 24;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 26;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 30;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 34;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 40;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 49;
          
        }       
        
        if (nextDepth <= 10) {
          
          resid = 59;
          
        }        

      }
      
      if (surfaceGroup == 12) {
        
        if (nextDepth > 30) {
          
          // Error, user can't dive past 30 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 30) {
          
          resid = 17;
          
        }
        
        if (nextDepth <= 25) {
          
          resid = 22;
          
        }
        
        if (nextDepth <= 22) {
          
          resid = 25;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 28;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 32;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 37;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 43;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 53;
          
        }       
        
        if (nextDepth <= 10) {
          
          resid = 64;
          
        }
        
      }
      
      if (surfaceGroup == 13) {
        
        if (nextDepth > 25) {
          
          // Error, user can't dive past 25 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 25) {
          
          resid = 23;
          
        }
        
        if (nextDepth <= 22) {
          
          resid = 27;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 30;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 34;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 39;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 47;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 57;
          
        }
         
        if (nextDepth <= 10) {
          
          resid = 70;
          
        }
        
      }
      
      if (surfaceGroup == 14) {
        
        if (nextDepth > 25) {
          
          // Error, user can't dive past 25 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 25) {
          
          resid = 25;
          
        }
        
        if (nextDepth <= 22) {
          
          resid = 29;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 32;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 36;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 42;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 50;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 62;
          
        }        
        
        if (nextDepth <= 10) {
          
          resid = 75;
          
        }
        
      }
      
      if (surfaceGroup == 15) {
        
        if (nextDepth > 25) {
          
          // Error, user can't dive past 25 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 25) {
          
          resid = 26;
          
        }
        
        if (nextDepth <= 22) {
          
          resid = 30;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 34;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 39;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 45;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 53;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 66;
          
        }       
        
        if (nextDepth <= 10) {
          
          resid = 82;
          
        }       

      }
      
      if (surfaceGroup == 16) {
        
        if (nextDepth > 22) {
          
          // Error, user can't dive past 22 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 22) {
          
          resid = 55;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 36;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 41;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 48;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 57;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 71;
          
        }        
        
        if (nextDepth <= 10) {
          
          resid = 88;
          
        }        

      }
      
      if (surfaceGroup == 17) {
        
        if (nextDepth > 22) {
          
          // Error, user can't dive past 22 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 22) {
          
          resid = 34;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 38;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 43;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 50;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 61;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 76;
          
        }
               
        if (nextDepth <= 10) {
          
          resid = 95;
          
        }       

      }
      
      if (surfaceGroup == 18) {
        
        if (nextDepth > 20) {
          
          // Error, user can't dive past 20 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 40;
          
        }

        if (nextDepth <= 18) {
          
          resid = 46;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 53;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 64;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 82;
          
        }
                
        if (nextDepth <= 10) {
          
          resid = 104;
          
        }
        
      }
      
      if (surfaceGroup == 19) {
        
        if (nextDepth > 20) {
          
          // Error, user can't dive past 20 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 20) {
          
          resid = 42;
          
        }

        if (nextDepth <= 18) {
          
          resid = 48;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 56;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 67;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 88;
          
        }
                
        if (nextDepth <= 10) {
          
          resid = 112;
          
        }
         
      }
      
      if (surfaceGroup == 20) {
        
        if (nextDepth > 18) {
          
          // Error, user can't dive past 18 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 51;
          
        }

        if (nextDepth <= 16) {
          
          resid = 60;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 73;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 94;
          
        }       
        
        if (nextDepth <= 10) {
          
          resid = 122;
          
        }
        
      }
      
      if (surfaceGroup == 21) {
        
        if (nextDepth > 18) {
          
          // Error, user can't dive past 18 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 18) {
          
          resid = 53;
          
        }

        if (nextDepth <= 16) {
          
          resid = 63;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 77;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 101;
          
        }
                
        if (nextDepth <= 10) {
          
          resid = 133;
          
        }        

      }
      
      if (surfaceGroup == 22) {
        
        if (nextDepth > 16) {
          
          // Error, user can't dive past 16 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 67;
          
        }

        if (nextDepth <= 14) {
          
          resid = 82;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 108;
          
        }
                
        if (nextDepth <= 10) {
          
          resid = 145;
          
        }        

      }
      
      if (surfaceGroup == 23) {
        
        if (nextDepth > 16) {
          
          // Error, user can't dive past 16 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 16) {
          
          resid = 70;
          
        }

        if (nextDepth <= 14) {
          
          resid = 87;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 116;
          
        }        
        
        if (nextDepth <= 10) {
          
          resid = 160;
          
        }
        
      }
      
      if (surfaceGroup == 24) {
        
        if (nextDepth > 14) {
          
          // Error, user can't dive past 14 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 14) {
          
          resid = 92;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 125;
          
        }        
        
        if (nextDepth <= 10) {
          
          resid = 178;
          
        }
        
      }
      
      
      if (surfaceGroup == 25) {        
        
        if (nextDepth > 12) {
          
          // Error, user can't dive past 12 meters.
          resid = -1;
          
        }
        
        if (nextDepth <= 12) {
          
          resid = 134;
          
        }
       
        if (nextDepth <= 10) {
          
          
          
          resid = 199;
          
        }
        
      }
      
      if (surfaceGroup == 26) {
        
        // Error, user can't attempt any more dives.
        resid = -1;
        
      } 
      
    }

      // Returns whatever the residual nitrogen is, or -1 for any number of errors.
      return resid;
      
  }
        
}//end of class
